#include <algorithm>
using namespace std;
/*
 * @lc app=leetcode.cn id=50 lang=cpp
 *
 * [50] Pow(x, n)
 */

// @lc code=start
class Solution {
public:
    double myPow(double x, int n) {
        double res = 1; int nn = abs(n);
        while (nn > 0) {
            if (nn & 1) res = res * x;
            x = x * x;
            nn >>= 1;
        }  
        if (n < 0) res = 1 / res; 
        return res;
    }
};
// @lc code=end

